﻿using System;

namespace dbe.FoundationLibrary.Core.Win32.API
{
    /// <summary>
    /// 基于Win32 API的图形类，主要用于在Win32应用程序中进行图形绘制。
    /// </summary>
    public class Win32Graphics
    {
        /// <summary>
        /// 创建画笔
        /// </summary>
        /// <param name="nStyle">指定画笔的风格，取值来自WinGdi中的"Pen Styles"</param>
        /// <param name="nWidth"></param>
        /// <param name="crColor"></param>
        /// <returns></returns>
        public static IntPtr CreatePen(int nStyle, int nWidth, uint crColor)
        {
            return Gdi32.CreatePen(nStyle, nWidth, crColor);
        }

        /// <summary>
        /// 模仿MFC中的tagRECT创建RECT结构体
        /// </summary>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <param name="width"></param>
        /// <param name="height"></param>
        /// <returns></returns>
        public static tagRECT CreateRect(int x, int y, int width, int height)
        {
            return new tagRECT
            {
                Left = x,
                Top = y,
                Right = x + width, // 计算右边界
                Bottom = y + height // 计算下边界
            };
        }

        /// <summary>
        /// 获取颜色
        /// </summary>
        /// <param name="r"></param>
        /// <param name="g"></param>
        /// <param name="b"></param>
        /// <param name="a">默认Alpha值为0</param>
        /// <returns></returns>
        public static uint GetColor(byte r, byte g, byte b, byte a = 0)
        {
            return (uint)((a << 24) | ((b << 16) | (g << 8) | r));
        }

        /// <summary>
        /// 模仿MFC中的CreateFont生成字体句柄
        /// </summary>
        /// <param name="fontSize">字体大小</param>
        /// <param name="fontName">字体名称</param>
        /// <returns></returns>
        public static IntPtr GetFont(int fontSize, string fontName)
        {
            return Gdi32.CreateFont(fontSize, 0, 0, 0, WinGdi.FW_BOLD, 0, 0, 0, WinGdi.ANSI_CHARSET, WinGdi.OUT_DEFAULT_PRECIS,WinGdi.CLIP_DEFAULT_PRECIS, WinGdi.DEFAULT_QUALITY, WinGdi.DEFAULT_PITCH | WinGdi.FF_DONTCARE, fontName);
        }
    }
}